package load_balance

type LbType int

const (
	LbRandom LbType = iota
	LbRoundRobin
	LbWeightRoundRobin
	LbConsistentHash
)

func LoadBanlanceFactoryWithConf(lbType LbType, mConf LoadBalanceChecker) (lb LoadBalancer) {
	//观察者模式
	switch lbType {
	case LbRandom:
		lb = &RandomBalance{}
	case LbConsistentHash:
		lb = NewConsistentHashBanlance(10, nil)
	case LbRoundRobin:
		lb = &RoundRobinBalance{}
	case LbWeightRoundRobin:
		lb = &WeightRoundRobinBalance{}
	default:
		lb = &RandomBalance{}
	}
	mConf.Attach(lb)
	// 立即更新一次
	lb.Update(mConf.GetConf())
	return lb
}
